
$(function(){
    function render(data=[]){
        let html="";
           data.forEach((item,index)=>{
            if(index<4){
                html+=`
                <li productid=${item.productId} class="showcon">
                    <a href="#">
                    ${item.productImg}
                    <h3>${item.productName}</h3>
                    <p>${item.productPrice}</p>
                    <span>${item.productFrom} | ${item.productTime}</span>
                    </a>
                </li>
            `
            }
        }) 
       $('.product').html(html);
    }


    $.ajax({
        url:'http://chst.vip:1234/api/getinlanddiscount',
    }).then(res=>{
        console.log(res);
        render(res.result);
        $('.product').on('click','li',function(){
            //跳转到详情页
            //携带product参数
            let productid=$(this).attr('productid');
            location.href=`./inlandDiscount.html?productid=${productid}`
        })
    })
})